package com.app;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import android.content.Context;
import android.os.Environment;

import com.android.volley.BuildConfig;
import com.app.util.Utils_Log;

public class G {
	private static String TAG = G.class.getSimpleName();

	public static boolean DEBUG = BuildConfig.DEBUG;
	
	public static boolean bUtils_log_file = false; // log是否写入到本地文件
	
	
	
	
	
	
	
	
	
	public static String PATH_DB =""; // 在provider中动态得到
	
	
	
	public static String PATH_LOG = "";
	 
	
	public static String PACK_NAME = "";
	
	
	// 外部初始化入口
	public static void init( Context context, Map<String, Object> map) {
		
		try {
			initSavePath(context);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		PATH_DB = (String)map.get("DBPath");
		
		
		
		Utils_Log.e(TAG, "PATH_DB: "+PATH_DB);
		Utils_Log.e(TAG, "PATH_LOG: "+PATH_LOG);
		
	}
	
	
	private static void initSavePath(Context context) throws IOException {

		boolean INSIDE = false;		// 是否保存在应用安装目录下
		
		// 得到包名
		PACK_NAME = context.getPackageName();

		
		// 扩展储存是否存在
		boolean sdcardExist = Environment.getExternalStorageState().equals(
				android.os.Environment.MEDIA_MOUNTED);
		
		if( sdcardExist ){
			File sdCardpath = Environment.getExternalStorageDirectory();
			File dbPath = new File(sdCardpath, PACK_NAME);
			String str_dir = dbPath.getPath();
			if (INSIDE) // 保存在包内，这样卸载应用程序，内部的图片也会被删除; (inside话，拍照图片无法保存）
				str_dir = context.getCacheDir().getPath();
			File dir = new File(str_dir, "tmp/log"); // /mnt/sdcard/***/file
			if (!dir.exists())
				dir.mkdirs();
			
			// 保存路径
			PATH_LOG = dir.getAbsolutePath();
		}
		else{
			File dir = new File(context.getCacheDir(), "tmp/log"); // 
			if (!dir.exists())
				dir.mkdirs();
			
			// 保存路径
			PATH_LOG = dir.getAbsolutePath();
		}
		
	
		
		
		

	}

	
	
}
